package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetListMessegerRequest;
import keeto.com.vn.bms.network.response.GetListMessegerResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetListMesseger extends AbstractTask {
	private int type;
	private int pageLimit;
	private int pageNumber;
	private String Authkey;

	public TaskGetListMesseger(BMSListener listener, IBMSCore core,int type,int pagelimit,int pageNumber,String authkey) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.type =type;
		this.pageLimit = pagelimit;
		this.pageNumber = pageNumber;
		this.Authkey = authkey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
	IOException {
		// TODO Auto-generated method stub
		GetListMessegerRequest request = new GetListMessegerRequest();
		request.setType(type);
		request.setPageLimit(pageLimit);
		request.setPageNumber(pageNumber);
		request.setAuthKey(Authkey);
		GetListMessegerResponse response = protocol.getListMesseger(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetListMesseger(response.getReturnCode(),response.getPageCount(),response.getListMsg());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetListMesseger(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, IBMSConfig.UNINITIALIZED_INT,null);
		}
	}

}
